package pe.edu.sistemas.postgrado.samupg.view.controller;

import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import pe.edu.sistemas.postgrado.samupg.business.service.planificacion.MaestriaDiplomadoService;
import pe.edu.sistemas.postgrado.samupg.domain.model.MaestriaDiplomado;

/**
 *
 * @author Marlon
 */
@ManagedBean
@Scope("view")
@Controller
public class GestionCursosController {

    private List<MaestriaDiplomado> listMaestrias;
    private List<MaestriaDiplomado> listDiplomados;
    private MaestriaDiplomado maestriaDiplomadoNuevo;
    @Resource
    private MaestriaDiplomadoService maestriaDiplomadoService;
    private boolean correcto;

    /**
     * Creates a new instance of GestionCursosController
     */
    public GestionCursosController() {
        maestriaDiplomadoNuevo = new MaestriaDiplomado();
        correcto = false;
    }

    @PostConstruct
    public void init() {
        listMaestrias = maestriaDiplomadoService.getMaestrias();
        listDiplomados = maestriaDiplomadoService.getDiplomados();
    }

    public void guardarCursoListener() {
        maestriaDiplomadoService.crearMaestriaDiplomado(maestriaDiplomadoNuevo);
        FacesContext.getCurrentInstance().addMessage("growl", new FacesMessage(FacesMessage.SEVERITY_INFO,
                "Se registró satisfactoriamente el curso", ""));

        // si se ingreso una maestria
        if (maestriaDiplomadoNuevo.getMdEstado() == 0) {
            listMaestrias = maestriaDiplomadoService.getMaestrias();
        } else {
            listDiplomados = maestriaDiplomadoService.getDiplomados();
        }

        maestriaDiplomadoNuevo = new MaestriaDiplomado();
    }

    public List<MaestriaDiplomado> getListMaestrias() {
        return listMaestrias;
    }

    public void setListMaestrias(List<MaestriaDiplomado> listMaestrias) {
        this.listMaestrias = listMaestrias;
    }

    public List<MaestriaDiplomado> getListDiplomados() {
        return listDiplomados;
    }

    public void setListDiplomados(List<MaestriaDiplomado> listDiplomados) {
        this.listDiplomados = listDiplomados;
    }

    public MaestriaDiplomado getMaestriaDiplomadoNuevo() {
        return maestriaDiplomadoNuevo;
    }

    public void setMaestriaDiplomadoNuevo(MaestriaDiplomado maestriaDiplomadoNuevo) {
        this.maestriaDiplomadoNuevo = maestriaDiplomadoNuevo;
    }

    public boolean isCorrecto() {
        return correcto;
    }

    public void setCorrecto(boolean correcto) {
        this.correcto = correcto;
    }
}
